package com.xc.erp.modules.erp.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xc.erp.modules.erp.mapper.JshMaterialCategoryMapper;
import com.xc.erp.modules.erp.domain.pojo.JshMaterialCategory;
import com.xc.erp.modules.erp.service.JshMaterialCategoryService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Administrator
 * @description 针对表【jsh_material_category(产品类型表)】的数据库操作Service实现
 * @createDate 2022-12-15 10:59:10
 */
@Service
public class JshMaterialCategoryServiceImpl extends ServiceImpl<JshMaterialCategoryMapper, JshMaterialCategory>
        implements JshMaterialCategoryService {

    @Override
    public List<JshMaterialCategory> getTree() {
        List<JshMaterialCategory> list = list();
        //存储需要删除的元素
//        ArrayList<JshMaterialCategory> remove = new ArrayList<>();
//        for (JshMaterialCategory materialCategory : list) {
//            ArrayList<JshMaterialCategory> children = new ArrayList<>();
//            for (int i = 0; i < list.size(); i++) {
//                //判断有没有子菜单
//                if (String.valueOf(materialCategory.getId()).equals(String.valueOf(list.get(i).getParentId()))) {
//                    //添加到子菜单
//                    children.add(list.get(i));
//                    //有子菜单删除
//                    remove.add(list.get(i));
//                }
//            }
//            //子菜单添加没有就添加null
//            if (children.size() == 0)
//                materialCategory.setChildren(null);
//            else
//                materialCategory.setChildren(children);
//        }
//        // 删除list中为子菜单中的元素
//        for (int i = 0; i < remove.size(); i++) {
//            list.remove(remove.get(i));
//        }
        return list;
    }
}




